def argmin(points, key=None, need_value=False):
    if key is None:
        idx, value = min(enumerate(points), key=lambda x: x[1])
    else:
        idx, value = min(enumerate(points), key=lambda x: key(x[1]))
    if need_value:
        return idx, value
    return idx


def argmax(points, key=None, need_value=False):
    if key is None:
        idx, value = max(enumerate(points), key=lambda x: x[1])
    else:
        idx, value = max(enumerate(points), key=lambda x: key(x[1]))
    if need_value:
        return idx, value
    return idx
